/*
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package hextd.server;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Set;

public class UserRights {

	public enum Right {

		kick,
		maps
	}
	private HashMap<String, Set<Right>> rightsTable;

	public UserRights() {
	}

	/**
	 * Turns a comma separated list of external groups in a set of rights.
	 */
	public Set<Right> getRightsForGroups(String in) {
		Set<Right> retval = EnumSet.noneOf(Right.class);
		String[] groups = in.split(",");
		for (String group : groups) {
			retval.addAll(rightsTable.get(group));
		}
		return retval;
	}

	public void addRightToGroup(String group, Right right) {
		Set<Right> rights = rightsTable.get(group);
		if (rights == null) {
			rights = EnumSet.noneOf(Right.class);
			rightsTable.put(group, rights);
		}
		rights.add(right);
	}
}
